#include <windows.h>
#include <stdio.h>

int main() {
    char path[MAX_PATH];
    // 获取当前 exe 的路径（C 程序所在目录）
    GetModuleFileNameA(NULL, path, MAX_PATH);

    // 去掉可执行文件名，得到目录
    char* lastSlash = strrchr(path, '\\');
    if (lastSlash) *lastSlash = '\0';

    // 拼接 pythonw.exe 和 main.py 的路径
    char command[MAX_PATH + 50];
    sprintf(command, "%s\\python-3.12.10-embed-amd64\\pythonw.exe %s\\main.py", path, path);

    STARTUPINFO si = { sizeof(si) };
    PROCESS_INFORMATION pi;

    BOOL success = CreateProcess(
        NULL, command, NULL, NULL, FALSE,
        CREATE_NO_WINDOW, NULL, NULL, &si, &pi
    );

    if (!success) {
        MessageBoxA(NULL, "Failed to start Python!", "Error", MB_ICONERROR);
        return 1;
    }

    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
    return 0;
}
